<template>
  <a-modal
    :width="modalWidth"
    :visible="visible"
    title="订单分成详情"
    @cancel="handleCancel"
    @ok="handleCancel"
    cancelText="关闭"
  >
    <a-table
      class="table"
      :loading="loading"
      :scroll="{ x: 1000 }"
      :row-key="record => record.id"
      :columns="columns"
      :data-source="dataSource"
      :pagination="false"
    />
  </a-modal>
</template>

<script>
import { getAction } from '@api/manage'
import Api from '@/api/OrderManage/OnlineOrders'
import { formatAmountFromFenToYuan } from '@/utils/util'
import { filterDictText, initDictOptions } from '@comp/dict/JDictSelectUtil'

export default {
  name: 'OrderSharing',
  data() {
    return {
      id: '',
      modalWidth: '70%',
      visible: false,
      loading: false,
      dataSource: [],
      sharingTypeOptions: [],
      columns: [
        {
          title: '分佣人',
          align: 'center',
          dataIndex: 'sharingPeople'
        },
        {
          title: '分佣人类型',
          align: 'center',
          dataIndex: 'sharingType',
          customRender: (text, record, index) => {
            //字典值替换通用方法
            return filterDictText(this.sharingTypeOptions, text)
          }
        },
        {
          title: '比例',
          align: 'center',
          dataIndex: 'proportion',
          customRender(text, record, index) {
            return `${text}${text?'%':''}`
          }
        },
        {
          title: '金额(元)',
          dataIndex: 'amount',
          align: 'center',
          customRender: (text, record, index) => {
            return formatAmountFromFenToYuan(text)
          }
        }
      ]
    }
  },
  created() {
    initDictOptions('sharingType').then(res => {
      if (res.success) {
        this.sharingTypeOptions = res.result
      }
    })
  },
  methods:{
    handleCancel() {
      this.close()
    },
    async showModal(id) {
      this.visible = true
      this.id = id
      this.loadData()
    },
    close() {
      this.visible = false
    },
    loadData() {
      if (this.id) {
        this.loading = true
        getAction(Api.orderSharing + this.id).then(res => {
          if (res.code === 200) {
            this.dataSource = res.result
          }
          this.loading = false
        })
      }
    }
  }
}
</script>

<style scoped>

</style>